package by.bsuir.sn.view
{
	import by.bsuir.sn.com.terralever.util.Enumerator;

	import by.bsuir.sn.util.ObjUtil;

	import by.bsuir.sn.view.renderer.DeleteButtonRenderer;

	import mx.collections.IList;
	import mx.controls.Button;
	import mx.controls.DataGrid;
	import mx.controls.DateField;
	import mx.controls.dataGridClasses.DataGridColumn;
	import mx.core.ClassFactory;

	public class DataGridExt extends DataGrid
	{

		[Inspectable(category="Data",defaultValue="undefined")]
		override public function set dataProvider(value : Object) : void
		{
			columns = [];
			var cs : Array = [];
			var item : * = IList(value).getItemAt(0);
			var c : DataGridColumn;
			for each (var prop : String in ObjUtil.getProperties(item))
			{
				if (ObjUtil.getName(item[prop]).toLowerCase().indexOf("collection") != -1)
					continue;
				c = new DataGridColumn(prop);
				if(prop.toLowerCase().indexOf("date") != -1)
					c.itemEditor = new ClassFactory(DateField);
				cs.push(c);
			}
			c = new DataGridColumn();
			c.editable = false;
			c.width = 80;
			c.itemRenderer = new ClassFactory(DeleteButtonRenderer);
			cs.push(c);
			columns = cs;

			super.dataProvider = value;
		}
	}
}
